#include<iostream>
using namespace std;
typedef struct node
{
	struct node *lchild;
	struct node *rchild;
	char data;
 }BTnode;
 typedef struct node *tree;
BTnode *creattree(char *pre,char *in,int n)
{
	BTnode *b;
	char *p;
	if(n==0)return 0;
	b=new node;
	b->data=*pre;
	for(p=in;p<in+n;p++)
		if(*p==*pre)
		break;
	int k=p-in;
	b->lchild=creattree(pre+1,in,k);
	b->rchild=creattree(pre+k+1,p+1,n-k-1);
	return b;
}
int height(BTnode *b)
{
	int l,r;
	if(b==NULL)return (0);
	else
	{
		l=height(b->lchild);
		r=height(b->rchild);
		return(l>r)?(l+1):(r+1); 
	}
 }
 int main() 
{
	int n,h;
	char pre[50],in[50];
	BTnode *b;
	cin>>n>>pre>>in;
	b=creattree(pre,in,n);
	h=height(b);
	cout<<h;
	return 0;
}
